package com.japp.manager.web;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.japp.base.BaseAction;
import com.japp.manager.bean.DataBean;
import com.japp.manager.service.DataService;
import com.japp.sys.service.SelectService;
/**
 * 数据管理
 * @author Administrator
 *
 */
@Scope("prototype")
@Controller
public class DataAction extends BaseAction<DataBean> {

	private static final long serialVersionUID = -5677670163048708848L;
	@Autowired
	private DataService dataService;
	@Autowired
	private SelectService selectService;
	private DataBean data = new DataBean();
	private Map<String, String> map = null;
	
	/**
	 * 查询
	 * @return
	 */
	public String queryData(){
		String power = session.getAttribute("u_power").toString();
		String dpid = session.getAttribute("userltd").toString();
		//String dpcode = session.getAttribute("userltdcode").toString();
		String usercode = session.getAttribute("u_code").toString();
		//部门
		if("2".equals(power)){
			data.setSubmit_dpid(dpid);
		//业务员
		}else if("3".equals(power)){
			data.setSubmit_ucode(usercode);
		}
		map = selectService.getSelMapByString(data.getData_type());
		page = dataService.getPage(page, data);
		return SUCCESS;
	}
	/**
	 * 查看
	 * @return
	 */
	public String findDataView(){
		map = selectService.getSelMapByString(data.getData_type());
		if(data.getId()!=0){
			data = dataService.findDataById(data.getId());
		}
		return "dataView";
	}
	/**
	 * 欲新增 以及更新 
	 * @return dataView dataDetil
	 */
	public String findDataDetil(){
		map = selectService.getSelMapByString(data.getData_type());
		if(data.getId()!=0){
			data = dataService.findDataById(data.getId());
		}
		return "dataDetil";
	}
	/**
	 * 删除
	 * @return
	 */
	public void deleteDataById(){
		int rel = dataService.deleteData(keys);
		if(rel>0){
			result = "删除成功!";
		}else {
			result = "删除失败!";
		}
		wPrint(result);
	}
	/**
	 * 更新
	 * @return
	 */
	public void updateDataById(){
		int rel = dataService.updateData(data);
		if(rel>0){
			result = String.valueOf(data.getId());
		}else {
			result = "error";
		}
		wPrint(result);
	}
	/**
	 * 新增
	 */
	public void insertDataById(){
		int rel = dataService.insertData(data);
		if(rel>0&&data.getId()!=0){
			result = ""+data.getId();
		}else {
			result = "0";
		}
		wPrint(result);
	}
	public DataBean getData() {
		return data;
	}
	public void setData(DataBean data) {
		this.data = data;
	}
	public Map<String, String> getMap() {
		return map;
	}
	public void setMap(Map<String, String> map) {
		this.map = map;
	}
	
	
}

